{*******************************************************************************
* The contents of this file are used with permission, subject to the Mozilla   *
* Public License Version 1.1 (the "License"); you may not use this file except *
* in compliance with the License. You may obtain a copy of the License at      *
* http://www.mozilla.org/MPL/                                                  *
*                                                                              *
* Software distributed under the License is distributed on an "AS IS" basis,   *
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for *
* the specific language governing rights and limitations under the License.    *
*                                                                              *
* The Original Code is distributed as part of the "mediate" product and is     *
* Copyright (C) @home media limited. All Rights Reserved.                      *
*                                                                              *
* Email: support@athomemedia.co.uk                                             *
* Web:   http://www.athomemedia.co.uk                                          *
*******************************************************************************}

unit GirderAPI;
{
   Girder 3.2+ API Header
   May 4th 2002
   Copyright Ron Bessems


   When contributing plugins to Girder please consider releasing the sourcecode
   to the public or to Ron. In the past we have had some binary only plugins 
   that needed modification but we where unable to contact the author thus loosing
   valuable work. When releasing the code to Ron it is possible to do this under
   a NDA.

   Reimplementation of the Girder API in programs other then Girder is stricktly prohibited.

   Girder developers homepage

   http://www.girder.nl/developer.php
   
   Questions go to 
   
   http://www.girder.nl/phpBB2/

   or directly to Ron at,

   developer@girder.nl


   updates:
   -- September 22 2002, version 2 this is not yet finished use API version 2 on own risk.
   -- October 10 2002, version 2 finalized, no changes.
}
interface

uses
  Windows, SysUtils;

const
// return values of the gir_event function
  retContinue       = 0;   // Girder will continue working normally
  retExplicitReturn = 1;   // Girder will stop after this command in the current Multigroup but continues on elsewhere.
  retStopProcessing = 2;   // Girder will stop processing this event completely.

// The OSD settings for use with get_osd_settings
  osdFGColor          = 1;
  osdFGDColor         = 2;
  osdBGColor          = 3;
  osdWidth            = 4;
  osdHeight           = 5;
  osdCaption          = 6;
  osdBorder           = 7;
  osdTransparent      = 8;
  osdFontsize         = 9;
  osdFontWeight       = 10;
  osdFontItalic       = 11;
  osdFontUnderline    = 12;
  osdFontStrikeout    = 13;
  osdLeft             = 14;
  osdTop              = 15;
  osdCenter           = 16;
  osdMonitor          = 17;

// generic return values
  GIR_TRUE            = 1;
  GIR_FALSE           = 0;
  GIR_ASYNC_LEARN     = 2;

// gir_info messages
  GIRINFO_QUERYUNLOAD = 1;
{
   If you return GIR_FALSE Girder will query the plugin again 500 milliseconds later. If you
   return GIR_TRUE girder will not ask again and unload the plugin as soon as all other plugins
   agreed to unload.

   The wparam in QUERY_UNLOAD contains the number of requests left before Girder closes
   the plugin anyway no matter what you return.

}
  GIRINFO_POWERBROADCAST = 2;
{
 this passes the wparam and lparam directly from the WM_POWERBROADCAST,
   to confirm the message pass GIR_TRUE.
}

{ Currently not yet supported }
  GIRINFO_WINLOGON       = 3;

{ Wparam for GIRINFO_WINLOGON can be : }
  WL_LOGON              = 0;
  WL_LOGOFF             = 1;
  WL_STARTUP            = 2;
  WL_SHUTDOWN           = 3;
  WL_STARTSCREENSAVER   = 4;
  WL_STOPSCREENSAVER    = 5;
  WL_STARTSHELL         = 6;
  WL_LOCK               = 7;
  WL_UNLOCK             = 8;

{ This message is sent when the girder GUI window closes,
   you could close the plugin windows if needed }
  GIRINFO_MAINWIN_CLOSE = 4;
{ This message is sent when the girder GUI window opens }
  GIRINFO_MAINWIN_OPEN  = 5;
{ This message is sent when the scripting engine changes state }
  GIRINFO_SCRIPT_STATE  = 6;

type
// the command structure that girder passes to the plugin.
  p_command = ^t_command;
  t_command = record
    critical_section:_RTL_CRITICAL_SECTION;
    Name            : PChar;
    ActionType      : Integer;
    ActionSubType   : Integer;
    sValue1         : PChar;
    sValue2         : PChar;
    sValue3         : PChar;
    bValue1         : Integer;
    bValue2         : Integer;
    bValue3         : Integer;
    iValue1         : Integer;
    iValue2         : Integer;
    iValue3         : Integer;
    lValue1         : Integer;
    lValue2         : Integer;
    lValue3         : Integer;
    Binary          : PByteArray;
    Size            : Integer;
  end;

  PointerToPChar = ^PChar;
// Girder exports a few functions here are the required typedefs

  t_target_callback    = procedure(HWN: HWND; command: p_command); stdcall;
  t_set_command        = procedure(command: p_command);stdcall;
  t_target_enum        = procedure(id: Integer; callback: t_target_callback); stdcall;
  t_realloc_pchar      = procedure(old: PointerToPchar; newPChar: PChar); stdcall;
  t_show_osd           = procedure(timer: Integer); stdcall;
  t_hide_osd           = procedure(); stdcall;
  t_start_osd_draw     = function(var hwn: HWND; var dc: HDC; user: Integer): Integer; stdcall;
  t_stop_osd_draw      = procedure(dc: HDC); stdcall;
  t_treepicker_show    = function(parent: HWND; command_id: Integer): Integer; stdcall;
  t_event_cb           = function(eventstring: PChar; device: Integer; payload: Pointer; len: Integer): Integer; stdcall;
  t_register_cb        = function(id: Integer; event_cb: t_event_cb; prefix: PChar; source_id: Integer): Integer; stdcall;
  t_get_link_name      = function(lvalue: Integer; store : PChar; size : Integer): Integer; stdcall;
  t_parse_girder_reg   = function(orig: PChar; store: PChar; size: Integer): Integer; stdcall;
  t_i18n_translate     = function(orig: PChar; store: PChar; size: Integer): Integer; stdcall;
  t_get_osd_settings   = function(setting: Integer): DWORD ; stdcall;
  t_get_osd_fontname   = function(store: PChar; size: Integer ): Integer; stdcall;
  t_run_parser         = function(str: PChar; error_value: pInteger ): Integer; stdcall;
  t_get_int_var        = function(name: PChar): Integer; stdcall;
  t_get_double_var     = function(name: PChar): Double; stdcall;
  t_get_string_var     = function(name: PChar; buffer: PChar; len: Integer): Integer; stdcall;
  t_set_int_var        = function(name: PChar; value: Integer): Integer; stdcall;
  t_set_double_var     = function(name: PChar; value: Double): Integer; stdcall;
  t_set_string_var     = function(name: PChar; value: PChar): Integer; stdcall;
  t_delete_var         = procedure(name: PChar); stdcall;
  t_gir_malloc         = function(size: Integer ): Pointer; stdcall;
  t_gir_free           = procedure(p: Pointer); stdcall;
  t_send_event         = function(eventstring: PChar; payload: pbytearray; len: Integer; device: Integer): Integer; stdcall;
  t_trigger_command    = function(command_id: Integer): Integer; stdcall;

  t_target_callback_ex       = procedure(HWN: HWND; command: p_command; data: Pointer); stdcall; // !JJ!
  t_target_enum_ex           = procedure(id: Integer; callback: t_target_callback_ex; data: Pointer); stdcall; // added user data !JJ!
  t_open_script_editor       = function(HWN: HWND; script: PChar): PChar; stdcall; // call from its own thread. free return pchar with gir_free.
  t_get_variable_type        = function(name: PChar): Integer; stdcall; // 1 = int, 2 = double, 3 = string, -1 = does not exists.
  t_open_list_variables      = function(): Integer; stdcall; // call to list all vars.
  t_get_first_variable       = function(): Integer; stdcall; // move to the beginning of the list
  t_close_list_variables     = function(): Integer; stdcall; // close the list var MUST DO!
  t_get_next_int_variable    = function(name: PChar; len: Integer; value: Integer): Integer; stdcall;
  t_get_next_double_variable = function(name: PChar; len: Integer; value: Double): Integer; stdcall;
  t_get_next_string_variable = function(name: PChar; len: Integer; value: PChar; size: Integer): Integer; stdcall;
  t_set_variable_window      = function(window: HWND; msg: Cardinal; add: Integer): Integer; stdcall; // call this to be notified of variable changes.
  t_get_script_state         = function(): Pointer; // call this to get the lua/script state, CHECK IF RETURN VALUE IS NOT NULL!!


// this is the version 1 export function structure as passed to gir_open
  p_functions = ^t_functions;
  t_functions = packed record // !JJ!
    size                    : DWORD;
    parse_girder_reg        : t_parse_girder_reg;
    get_link_name           : t_get_link_name;
    set_command             : t_set_command;
    target_enum             : t_target_enum;
    realloc_pchar           : t_realloc_pchar;
    show_osd                : t_show_osd;
    hide_osd                : t_hide_osd;
    start_osd_draw          : t_start_osd_draw;
    stop_osd_draw           : t_stop_osd_draw;
    treepicker_show         : t_treepicker_show;
    register_cb    	        : t_register_cb;
    i18n_translate 	        : t_i18n_translate;
    get_osd_settings 	      : t_get_osd_settings;
    get_osd_fontname 	      : t_get_osd_fontname;
    gir_malloc     	        : t_gir_malloc;
    gir_free       	        : t_gir_free;
    get_int_var    	        : t_get_int_var;
    get_double_var  	      : t_get_double_var;
    get_string_var  	      : t_get_string_var;
    set_int_var     	      : t_set_int_var;
    set_double_var  	      : t_set_double_var;
    set_string_var  	      : t_set_string_var;
    delete_var     	        : t_delete_var;
    run_parser  	          : t_run_parser;
    send_event		          : t_send_event;
    trigger_command	        : t_trigger_command;
    parent_hwnd             : HWND;
  end;

// this is the version 2 export function structure as passed to gir_open
  p_functions_2 = ^t_functions_2;
  t_functions_2 = packed record // !JJ!
    size                    : DWORD;
    parse_girder_reg        : t_parse_girder_reg;
    get_link_name           : t_get_link_name;
    set_command             : t_set_command;
    target_enum_ex          : t_target_enum_ex; // !JJ!
    realloc_pchar           : t_realloc_pchar;
    show_osd                : t_show_osd;
    hide_osd                : t_hide_osd;
    start_osd_draw          : t_start_osd_draw;
    stop_osd_draw           : t_stop_osd_draw;
    treepicker_show         : t_treepicker_show;
    register_cb    	        : t_register_cb;
    i18n_translate 	        : t_i18n_translate;
    get_osd_settings 	      : t_get_osd_settings;
    get_osd_fontname 	      : t_get_osd_fontname;
    gir_malloc     	        : t_gir_malloc;
    gir_free       	        : t_gir_free;
    get_int_var    	        : t_get_int_var;
    get_double_var  	      : t_get_double_var;
    get_string_var  	      : t_get_string_var;
    set_int_var     	      : t_set_int_var;
    set_double_var  	      : t_set_double_var;
    set_string_var  	      : t_set_string_var;
    delete_var     	        : t_delete_var;
    run_parser  	          : t_run_parser;

    get_variable_type       : t_get_variable_type ;
    open_list_variables     : t_open_list_variables;
    get_first_variable      : t_get_first_variable;
    close_list_variables    : t_close_list_variables ;
    get_next_int_variable   : t_get_next_int_variable;
    get_next_double_variable: t_get_next_double_variable;
    get_next_string_variable: t_get_next_string_variable;
    set_variable_window     : t_set_variable_window;
    get_script_state        : t_get_script_state;

    send_event		          : t_send_event;
    open_script_editor      : t_open_script_editor;
    trigger_command	        : t_trigger_command;
    parent_hwnd             : HWND;
  end;

implementation
end.

